# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=allegro

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.0.10
pkgrel=2
pkgdesc="Portable library mainly aimed at video game and multimedia programming (mingw-w64)"
arch=(any)
url="http://alleg.sourceforge.net"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
      "${MINGW_PACKAGE_PREFIX}-cmake"
      "${MINGW_PACKAGE_PREFIX}-freetype"
      "${MINGW_PACKAGE_PREFIX}-physfs"
      "${MINGW_PACKAGE_PREFIX}-libvorbis"
      "${MINGW_PACKAGE_PREFIX}-flac"
      "${MINGW_PACKAGE_PREFIX}-libpng"
      "${MINGW_PACKAGE_PREFIX}-openal"
      "${MINGW_PACKAGE_PREFIX}-dumb"
      "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
optdepends=(
    "${MINGW_PACKAGE_PREFIX}-dumb: allegro_audio"
    "${MINGW_PACKAGE_PREFIX}-flac: allegro_audio"
    "${MINGW_PACKAGE_PREFIX}-freetype: allegro_font"
    "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo: allegro_image"
    "${MINGW_PACKAGE_PREFIX}-libpng: allegro_image"
    "${MINGW_PACKAGE_PREFIX}-libvorbis: allegro_audio"
    "${MINGW_PACKAGE_PREFIX}-openal: allegro_audio"
    "${MINGW_PACKAGE_PREFIX}-physfs: allegro_physfs")
options=('strip' 'staticlibs')
source=("http://downloads.sourceforge.net/alleg/allegro-$pkgver.tar.gz")
conflicts=("${MINGW_PACKAGE_PREFIX}-allegro-static")
provides=("${MINGW_PACKAGE_PREFIX}-allegro-static")
sha256sums=('71b81080f34f6e485edd0c51f22923c18ff967d5db438e591e6f3885d5bdcda1')

prepare() {
  cd "$srcdir/allegro-$pkgver"
  sed -i "s,DS3DALG_DEFAULT,GUID_NULL,g" "addons/audio/dsound.cpp"
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null
  
  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null

  export DXSDK_DIR=${PREFIX_DEPS}/${MINGW_CHOST}
  mkdir "$srcdir/build-${MINGW_CHOST}" && cd "$srcdir/build-${MINGW_CHOST}"
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DCMAKE_BUILD_TYPE=Release \
    -DWANT_DEMO=OFF \
    -DWANT_DOCS=OFF \
    -DWANT_EXAMPLES=OFF \
    -DINSTALL_PKG_CONFIG_FILES=ON \
    ../${_realname}-${pkgver}
  make
}

package() {
  cd "$srcdir/build-${MINGW_CHOST}"
  make install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.bat' -o -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
